package com.gnerv.pabu.basic.core.listenter;

import com.gnerv.pabu.basic.core.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.sql.SQLOutput;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.IntSummaryStatistics;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import static java.util.Comparator.naturalOrder;

@Slf4j
@Component
public class KafkaListenter extends Thread {

    @KafkaListener(id = "monitor", groupId = "monitor", topics = {"kafkaLog"}, autoStartup = "false")
    public void listener(String data) {
        System.out.println(data);
    }


    public static void main(String[] args) {
        Map<String, User> maps = new HashMap<>(8);
        List<User> users = new ArrayList<>();
        User user = new User();
        user.setAccount("123");
        users.add(user);
        user = new User();
        user.setAccount("456");
        users.add(user);
        user = new User();
        user.setAccount("789");
        users.add(user);
        maps = users.stream().collect(Collectors.toMap(User::getAccount, item -> item));

        List<User> collect2 = users.stream().sorted(Comparator.comparing(User::getAccount)).collect(Collectors.toList());
        collect2.forEach(item -> System.out.println(item.toString()));
        List<User> collect3 = users.stream().sorted(Comparator.comparing(User::getAccount).reversed()).collect(Collectors.toList());
        collect3.forEach(item -> System.out.println(item.toString()));
        List<String> collect = users.stream().map(item -> item.getAccount()).collect(Collectors.toList());
        collect.stream().forEach(item -> System.out.println(item));
        List<User> collect1 = users.stream().filter(item -> "123".equals(item.getAccount())).collect(Collectors.toList());
        collect1.stream().forEach(item -> System.out.println(item));

        IntSummaryStatistics intSummaryStatistics = users.stream().mapToInt((item) -> Integer.valueOf(item.getAccount())).summaryStatistics();
        System.out.println(intSummaryStatistics);


        maps.forEach((k,v)-> System.out.println(k + v));
        List<User> collect4 = maps.entrySet().stream().map(item -> item.getValue()).collect(Collectors.toList());

        for (User user1 : collect4) {

        }

    }

}
